package com.sunhao.gulimall.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * 描述：GulimallSessionConfig 类的用途 SpringSession相关配置
 * 日期：2025/1/7
 */
@Configuration
public class GulimallSessionConfig {

    //设置session跨域
    @Bean
    public CookieSerializer cookieSerializer()
    {
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();

        cookieSerializer.setDomainName("gulimall.com");
        cookieSerializer.setCookieName("GULISESSION");

        return cookieSerializer;
    }

    //解决序列化
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer()
    {
        return new GenericJackson2JsonRedisSerializer();
    }
}
